<template>
  <div>
    <link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.8.0/skins/default/aliplayer-min.css"/>
    <script type="text/javascript" charset="utf-8"
            src="https://g.alicdn.com/de/prismplayer/2.9.17/aliplayer-min.js"></script>

    <!-- 请下载之后使用 -->
    <!--        <script type="text/javascript" charset="utf-8" src="/static/js/aliplayer-min.js"></script>-->
<!--    <div class="prism-player" id="player-con" style="height: 400px; width: 100%;"></div>-->
    <!--    <script type="text/template" id="endPreviewTemplate">-->
    <!--      <div class="vip_limit_content">-->
    <!--        <div class="vip_limit_wrap">-->
    <!--          <p class="title">Purchase Full Version</p>-->
    <!--          <div class="vip_limit_button_box">-->
    <!--            <a class="vip_limit_btn">Become VIP</a>-->
    <!--          </div>-->
    <!--          <div class="vip_limit_close"><span class="vip_limit_close_btn">x</span></div>-->
    <!--        </div>-->
    <!--      </div>-->
    <!--    </script>-->
    <div class="v-wrap">
      <div class="l-con">
        <div id="viewbox_report" class="video-info">
          <h1 class="video-title" title="第一节：Java简介">
            <span class="tit">第一节：Java简介</span>
          </h1>
          <div class="video-data">
            <span :title="playCount" class="view">{{video.playCount}}播放&nbsp;·&nbsp;</span>
<!--            <span title="历史累计弹幕数44413" class="mr5">总弹幕数4.4万</span>-->
            <span>{{video.gmtCreate}}</span>
          </div>
        </div>
        <div class="prism-player" id="player-con" style="height: 400px; width: 100%;"></div>
      </div>
      <div  class="r-con">
        <div  id="v_upinfo" class="up-info">
          <div  class="user-face"><a  :href="'/teacher/'+teacher.id" target="_blank"
                                                       class="u-face__avatar avatar-loaded">
            <div  class="bili-avatar"
                 style="width: 48px; height: 48px; transform: translate(0px, 0px);">
              <img :src="teacher.avatar" class="bili-avatar-img"> <span class="bili-avatar-icon bili-avatar-right-icon  bili-avatar-icon--personal bili-avatar-size-48"></span>
            </div>
          </a></div>
          <div  class="up-info_right">
            <div  class="name" style="line-height: 20px; height: 20px;">
              <a  :href="'/teacher/'+teacher.id" target="_blank" class="username " style="color: rgb(251, 114, 153);">{{teacher.teacherName}}
              <span  class="mask"></span></a>
<!--              <a href="$$" target="_blank" class="message"><i  class="el-icon-message"></i>发消息</a>-->
            </div>
            <div  title=" 微博/网易/Q音:xxxx  交流群2：xxxxx 商务、作品合作邮箱:xxxxxxx@163.com " class="desc">
              微博/网易/Q音:xxxx 交流群2：xxxxx 商务、作品合作邮箱:xxxxxxx@163.com
            </div>
          </div>
        </div>
        <div id="multi_page" class="multi-page report-wrap-module report-scroll-module">
          <div class="head-con">
            <div class="head-left"><h3 >视频选集</h3><span class="cur-page">(139/307)</span>
              <div class="range-box"><i  class="van-icon-general_viewlist"></i>
              </div>
            </div>
          </div>
          <div class="cur-list">
            <ul class="list-box">
              <li  v-for="(item,index) in videoList" :class="item.videoSourceId==vid?'on':''">
                <a  :title="item.title" class="router-link-active" @click="watchVideo(item.videoSourceId,item.chapterId)">
                <div class="clickitem">
                  <div class="link-content">
                    <img v-if="item.videoSourceId==vid" src="//s1.hdslb.com/bfs/static/jinkela/video/asserts/playing.gif" >
                    <span v-else></span>
                    <span class="page-num">P{{index+1}}</span>
                    <span class="part">{{item.title}}</span>
                  </div>
                  <div class="duration"></div>
                </div>
              </a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
  import vodApi from "../../api/vod";
  import cookie from "js-cookie";
  import courseApi from "../../api/course";

  export default {
    data(){
      return{
        vid:'',
        playAuth:'',
        chapterId:'',
        videoList:{},
        courseId: '',
        teacher:{
          id:'',
          avatar:'',
          teacherName:'',
        },
        video:{},
      }
    },
    created() {
      this.vid=this.$route.params.id;
      this.chapterId = this.$route.query.chapterId;
      this.courseId = this.$route.query.courseId;
      this.teacher.id = this.$route.query.teacherId;
      this.teacher.avatar = this.$route.query.avatar;
      this.teacher.teacherName = this.$route.query.teacherName;
      this.getVideoList();
      this.addViewCount();
    },
    methods:{
      //每浏览网页一次增加课程浏览量
      addViewCount(){
        vodApi.addPlayCount(this.vid)
          .then(resp=>{
            this.video = resp.data.data.video;
          });
      },

      watchVideo(videoId,chapterId){
          if(videoId==""){
            this.$message({
              message: "当前课程下暂无视频",
              type: "warning",
            })
          }
          else{
            const routeUrl = this.$router.resolve({
              path: '/player/'+videoId,
              query: {
                chapterId: chapterId,
                courseId: this.courseId,
                teacherName:this.teacher.teacherName,
                teacherId:this.teacher.id,
                avatar:this.teacher.avatar,
              }
            })
            window.open(routeUrl.href, '_self')
            // this.$router.push({path:'/player/'+videoId})
          }
      },

      //获取当前章节下面的所有小节
      getVideoList(){
        vodApi.getVideoByChapterId(this.chapterId)
        .then(resp=>{
          this.videoList=resp.data.data.videoList;
        })
      }
    },
    layout: 'video',//应用video布局
    asyncData({params, error}) {
      return vodApi.getPlayAuth(params.id)
        .then(resp => {
          return {
            playAuth: resp.data.data.playAuth,
            vid: params.id
          }
        })
    },
    //页面渲染后执行
    mounted() {
      new Aliplayer({
          "id": "player-con",
          "vid": this.vid,//视频id
          "playauth": this.playAuth,//视频凭证
          // "cover": 'https://online-education-study.oss-cn-beijing.aliyuncs.com/2022/M2L90_P%24YWKE%24XNVG558U%28M.jpg',//视频封面
          "qualitySort": "asc",//清晰度排序
          "format": "mp4",
          "mediaType": "video",//返回音频还是视频
          "width": "100%",//宽度比例
          "height": "500px",//高度
          "autoplay": false,//自动播放
          "isLive": false,//直播
          "rePlay": false,//循环播放
          "playsinline": true,//
          "preload": false,
          "language": "zh-cn",
          "controlBarVisibility": "hover",//控制条的显示方式：鼠标悬停
          "useH5Prism": true,//播放器类型:html5
        }, function (player) {
          console.log("播放器创建了。");
        }
      );
    }
  }
</script>

<style scoped>
  .prism-player .prism-cover {
    background-color: none;
    display: block;
  }

  .prism-player .prism-marker-text {
    display: none;
  }

  .vip-join {
    color: #00c1de;
  }

  .vip_limit_content {
    display: flex;
    width: 100%;
    height: 100%;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
  }

  .vip_limit_content .title {
    font-size: 18px;
    line-height: 36px;
    color: #fff;
    text-align: center;
    width: 100%;
  }

  .vip_limit_button_box {
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    width: 100%;
  }

  .vip_limit_btn {
    display: inline-block;
    min-width: 100px;
    position: relative;
    background: #f60;
    padding: 0 35px;
    margin: 0px 5px 20px 5px;
    border-radius: 38px;
    font-size: 18px;
    line-height: 38px;
    color: #623A0C;
    text-align: center;
    background-image: linear-gradient(-135deg, #FBE8A8 0%, #F8E7AC 15%, #E2C078 100%);
    cursor: pointer;
  }

  .vip_limit_close {
    text-align: center;
  }

  .vip_limit_close span {
    display: inline-block;
    width: 40px;
    height: 40px;
    line-height: 36px;
    background: rgba(165, 165, 165, 0.54);
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
  }

  .v-wrap {
    max-width: 1984px;
    min-width: 988px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
  }
  .l-con {
    width: 638px;
  }
  .v-wrap .video-info {
    height: 96px;
    padding-top: 27px;
    box-sizing: border-box;
  }
  .video-info .video-title {
    font-size: 18px;
    font-weight: 500;
    color: #212121;
    line-height: 26px;
    height: 26px;
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .video-info .video-data {
    font-size: 12px;
    height: 16px;
    color: #999;
    display: flex;
    align-items: center;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mr5 {
    margin-right: 5px;
  }
  .prism-player {
    background-color: #000;
    position: relative;
  }
  .prism-player video {
    position: absolute;
    left: 50%;
    top: 50%;
  }
  .v-wrap .r-con {
    width: 320px;
    flex: none;
    margin-left: 30px;
  }
  .v-wrap .up-info {
    box-sizing: border-box;
    height: 96px;
    padding-top: 15px;
    padding-bottom: 12px;
    display: flex;
  }
  .up-info .user-face {
    float: left;
    width: 48px;
    height: 48px;
    position: relative;
  }
  .bili-avatar {
    width: 50px;
    display: block;
    position: relative;
    background-size: cover;
    border-radius: 50%;
    margin: 0;
    padding: 0;
  }
  .bili-avatar-img {
    width: 48px;
    border: none;
    display: block;
    -o-object-fit: cover;
    object-fit: cover;
  }
  .up-info .up-info_right {
    width: 256px;
    height: 65px;
    margin-left: 27px;
    float: left;
  }
  .up-info .up-info_right .name .username {
    position: relative;
    font-size: 14px;
    color: #212121;
    font-weight: 500;
    display: inline-block;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: top;
  }
  .up-info .up-info_right .name .message {
    margin-left: 12px;
    font-size: 12px;
    color: #505050;
    display: inline-block;
    vertical-align: middle;
  }
  [class*=" el-icon-"], [class^=el-icon-] {
    font-family: element-icons!important;
    speak: none;
    font-style: normal;
    font-weight: 400;
    font-feature-settings: normal;
    font-variant: normal;
    text-transform: none;
    line-height: 1;
    vertical-align: baseline;
    display: inline-block;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  .up-info .up-info_right .desc {
    margin-top: 4px;
    width: 256px;
    font-size: 12px;
    line-height: 16px;
    height: 16px;
    color: #999;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .multi-page {
    position: relative;
    background: #f4f4f4;
    z-index: 1;
  }

  .multi-page .head-con {
    display: flex;
    align-items: center;
    color: #222;
    padding: 10px 16px 0;
    justify-content: space-between;
  }
  .multi-page .head-con .head-left {
    display: flex;
    align-items: center;
  }
  .multi-page .head-con .head-left h3 {
    font-size: 16px;
    font-weight: 400;
    margin-right: 8px;
  }
  .multi-page .head-con .head-left .cur-page {
    font-size: 12px;
    color: #999;
    line-height: 16px;
  }
  .multi-page .cur-list {
    padding: 4px 0;
    transition: all .3s;
  }
  .multi-page .cur-list .list-box {
    padding: 0 6px;
    max-height: 340px;
    overflow: auto;
    font-size: 12px;
  }
  .multi-page .cur-list .list-box li.on {
    background: #fff;
    padding: 0 10px 0 6px;
  }
  .multi-page .cur-list .list-box li {
    display: block;
    height: 30px;
    line-height: 30px;
    padding: 0 10px;
    color: #6d757a;
    margin: 5px 0;
    transition: all .3s;
    border-radius: 3px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
  }
  .multi-page .cur-list .list-box li a {
    display: block;
    color: #212121;
    display: flex;
    justify-content: space-between;
    overflow: hidden;
    text-decoration: none;
  }
  .multi-page .cur-list .list-box li .clickitem {
    display: flex;
    justify-content: space-between;
    overflow: hidden;
    width: 100%;
  }
  .multi-page .cur-list .list-box li .link-content {
    display: flex;
    align-items: center;
    flex-shrink: 1;
    overflow: hidden;
  }
  .multi-page .cur-list .list-box li.on img {
    display: block;
    height: 14px;
    width: 14px;
    font-size: 14px;
    margin-right: 5px;
  }
  .multi-page .cur-list .list-box li .page-num {
    margin-right: 10px;
  }
  .multi-page .cur-list .list-box li .part {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
  }


</style>

